package app;

import javax.servlet.annotation.WebServlet;

import utils.NavigatorUtils;

import com.vaadin.annotations.PreserveOnRefresh;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.Title;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.navigator.Navigator;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.UI;
import config.Parameters;

@PreserveOnRefresh
@SuppressWarnings("serial")
@Theme("Theme02")
@Title("Ajunt.Tavernes")
/**
 * Clase principal que hereda de UI crea el navigator que gestionara els views
 *
 */
public class V704UI extends UI {

	@WebServlet(value = "/*", asyncSupported = true)
	@VaadinServletConfiguration(productionMode = false, ui = V704UI.class)
	public static class Servlet extends VaadinServlet {
	}

	@Override
	protected void init(VaadinRequest request) {

		// Create a new instance of the navigator.
		// The navigator will attach itself automatically to this.

		Navigator navigator = new Navigator(this, this);

		try {
			// carreguem les vistes dels parametres marcades com ini
			NavigatorUtils.loadViewCatalogToNavigator(navigator);
			// anyadim un viewChangeListener al navigator
			NavigatorUtils.navigatorAddViewChangeListener(navigator);
			// anem a la vista de login
			NavigatorUtils.navigateTo(navigator, Parameters.LOGIN_VIEW_NAME);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	
	
}